package com.service.imp;
import com.dao.impl.SalerDaoImpl;
import com.dao.SalerDao;
import com.entity.Saler;
import com.service.BusinessService;
public class BusinessServiceImpl implements BusinessService {
//    private SalerDao salerDao = DaoFactory.getInstance().createDao("com.dao.impl.SalerDaoImpl", SalerDao.class);
private SalerDao salerDao = new SalerDaoImpl();
    public String  addSaler(Saler saler) {
        int result;
        try{
                if (salerDao.checkDuplicatedName(saler)){
                    result = salerDao.createNewAccount(saler);
                }else{
                    return "注册失败用户名已存在";
                }

            } catch (Exception e) {
                throw new RuntimeException(e);
        }
            if(result != 1){
                return "添加失败";
            }else{
                return "添加成功";
            }
    }

    public String updateSaler(Saler saler) {
        int result;
        try{
            result = salerDao.updateAccount(saler);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        if(result != 1){
            return "更新失败";
        }else{
            return "更新成功";
        }
    }
    public Saler getUserById(Long id){
        return salerDao.findById(id);
    }
    public Long checkPassword(String userName,String password){
        Saler saler = new Saler();
        saler.setAccountName(userName);
        saler.setPassWord(password);
        return salerDao.checkPass(saler);
    }

}
